package com.fsquare.domain.social;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import org.broadleafcommerce.profile.core.domain.Customer;
import org.broadleafcommerce.profile.core.domain.CustomerImpl;


@Entity
@Table(name = "SOCIAL_AUTH")
@NamedQueries( 
	    {   
	        @NamedQuery(name = "SOCIAL_TOKEN_BY_CUSTOMER_ID", query = "SELECT st FROM SocialTokenImpl st WHERE st.customer.id = :customerId"),
	        @NamedQuery(name = "SOCIAL_TOKEN_BY_KEY", query = "SELECT st FROM SocialTokenImpl st WHERE st.key = :key"),
	        @NamedQuery(name = "SOCIAL_TOKEN_BY_KEY_AND_PROVIDER", query = "SELECT st FROM SocialTokenImpl st WHERE st.key = :key AND st.provider = :provider"),
	        @NamedQuery(name = "SOCIAL_TOKEN_BY_DATE", query = "SELECT st FROM SocialTokenImpl st WHERE st.key = :key"),
	        @NamedQuery(name = "SOCIAL_TOKEN_BY_PROVIDER_AND_USERNAME", query = "SELECT st FROM SocialTokenImpl st WHERE st.provider = :provider AND st.username = :username")
	    }
	 )
public class SocialTokenImpl implements SocialToken ,Serializable{

	private static final long serialVersionUID = 6831625749574959739L;

	@Id
	@GeneratedValue
    private Long id;
	
	@Column(name = "TOKEN_PROVIDER", nullable=false)
    private String provider;
	
	@Column(name = "TOKEN_USERNAME", nullable=false)
    private String username;
	
    @Column(name = "TOKEN_KEY")
    private String key;

    @Column(name = "TOKEN_SECRET")
    private String secret;
    
    @ManyToOne (targetEntity = CustomerImpl.class)
    @JoinColumn(name = "CUSTOMER_ID", referencedColumnName = "CUSTOMER_ID", nullable=false)
    private Customer customer;
    
    
    @Column(name = "REQUEST_DATE")
    private Date requestDate;
    
    @Column(name = "TOKEN_ACTIVE")
    private boolean active = true;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getSecret() {
		return secret;
	}

	public void setSecret(String secret) {
		this.secret = secret;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public Date getRequestDate() {
		return requestDate;
	}

	public void setRequestDate(Date requestDate) {
		this.requestDate = requestDate;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	public String getProvider() {
		return provider;
	}

	public void setProvider(String provider) {
		this.provider = provider;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	
}
